home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / DTS Sample Code / System 7.0 Samples / CShell⁄THINK C / Utilities.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-20  |  25.2 KB  |  627 lines  |  [TEXT/MPS ]

  1. /*-----------------------------------------------------------------------------------------
  2. #
  3. #    Apple Macintosh Developer Technical Support
  4. #
  5. #    Collection of Utilities for DTS Sample code
  6. #
  7. #    Program:    Utilities.c.o
  8. #    File:        Utilities.h    -    Header for C Source
  9. #
  10. #    Copyright © 1988-1990 Apple Computer, Inc.
  11. #    All rights reserved.
  12. #
  13. -----------------------------------------------------------------------------------------*/
  14.  
  15. #ifndef __UTILITIES__
  16. #define __UTILITIES__
  17.  
  18. #ifdef applec
  19.  
  20. #    ifndef __TYPES__
  21. #        include <Types.h>
  22. #    endif
  23.  
  24. #    ifndef __QUICKDRAW__
  25. #        include <QuickDraw.h>
  26. #    endif
  27.  
  28. #    ifndef __DIALOGS__
  29. #        include <Dialogs.h>
  30. #    endif
  31.  
  32. #    ifndef __FILES__
  33. #        include <Files.h>
  34. #    endif
  35.  
  36. #    ifndef __MEMORY__
  37. #        include <Memory.h>
  38. #    endif
  39.  
  40. #    ifndef __OSUTILS__
  41. #        include <OSUtils.h>
  42. #    endif
  43.  
  44. #    ifndef __WINDOWS__
  45. #        include <Windows.h>
  46. #    endif
  47.  
  48. /* 
  49.  *    If we are using MPW 3.2 or later, GestaltEqu.h is included, otherwise we use
  50.  *    GestaltEqu31.h included in ::SC.025.Utilities:
  51.  */
  52. #    ifndef __GESTALTEQU__
  53. #        ifdef MPW32
  54. #            include <GestaltEqu.h>
  55. #        else
  56. #            include "GestaltEqu31.h"
  57. #        endif
  58. #    endif
  59.  
  60. /* 
  61.  *    If we are using MPW 3.2 or later, Folders.h is included, otherwise we use
  62.  *    definitions included in ::SC.025.Utilities:
  63.  */
  64. #    ifndef __FOLDERS__
  65. #        ifdef MPW32
  66. #            include <Folders.h>
  67. #        else
  68. #            include "Folders31.h"
  69. #        endif
  70. #    endif
  71.  
  72. #endif
  73.  
  74. #include "UtilitiesCommon.h"
  75.  
  76. /*-----------------------------------------------------------------------------------------
  77.     Global constants
  78. -----------------------------------------------------------------------------------------*/
  79. #ifndef applec
  80. #ifndef THINK_C
  81. #define nil                        0L
  82. #define _WaitNextEvent                    0xA860
  83. #define _InitGraf                        0xA86E
  84. #define _Unimplemented                    0xA89F
  85. /*
  86. #define screenActive            15    
  87. */
  88. #endif
  89. #endif
  90.  
  91. #ifndef THINK_C
  92. #define    kOSEvent                app4Evt        /* event used by MultiFinder */
  93. #define    kSuspendResumeMessage    1            /* high byte of suspend/resume event message */
  94. #define    kResumeMask                1            /* bit of message field for resume vs. suspend */
  95. #define    kMouseMovedMessage        0xFA        /* high byte of mouse-moved event message */
  96. #endif
  97. #define    kNoEvents                0            /* no events mask */
  98.  
  99. #define kDelayTime                8            /* For the delay time when flashing the
  100.                                                menubar and highlighting a button.
  101.                                                8/60ths of a second*/
  102.  
  103. #define kStartPtH                2            /* offset from the left of the screen */
  104. #define kStartPtV                2            /* offset from the top of the screen */
  105. #define kStaggerH                12            /* staggering amounts for new windows */
  106. #define kStaggerV                16
  107.  
  108. #define chBackspace                '\b'        /* ASCII code for Backspace character */
  109. #define chClear                    '\033'        /* ASCII code for Clear key (aka ESC) */
  110. #define chDown                    '\037'        /* ASCII code for down arrow */
  111. #define chEnd                    '\004'        /* ASCII code for the End key */
  112. #define chEnter                    '\003'        /* ASCII code for Enter character */
  113. #define chEscape                '\033'        /* ASCII code for Escape (aka Clear) key */
  114. #define chFunction                '\020'        /* ASCII code for any function key */
  115. #define chFwdDelete                '\177'        /* ASCII code for forward delete */
  116. #define chHelp                    '\005'        /* ASCII code for Help key */
  117. #define chHome                    '\001'        /* ASCII code for the Home key */
  118. #define chLeft                    '\034'        /* ASCII code for left arrow */
  119. #define chPageDown                '\f'        /* ASCII code for Page Down key */
  120. #define chPageUp                '\013'        /* ASCII code for Page Up key */
  121. #define chReturn                '\n'        /* ASCII code for Return character */
  122. #define chRight                    '\035'        /* ASCII code for right arrow */
  123. #define chSpace                    ' '            /* ASCII code for Space character */
  124. #define chTab                    '\t'        /* ASCII code for Tab character */
  125. #define chUp                    '\036'        /* ASCII code for up arrow */
  126.  
  127. enum { kQDOriginal = 0, kQD8Bit, kQD32Bit };    /* For use with gQDVersion */
  128.  
  129. /*-----------------------------------------------------------------------------------------
  130.     Types
  131. -----------------------------------------------------------------------------------------*/
  132.  
  133. typedef short *IntegerPtr, **IntegerHandle;
  134.  
  135. typedef long *LongintPtr, **LongintHandle;
  136.  
  137. typedef Boolean *BooleanPtr, **BooleanHandle;
  138.  
  139. #ifndef THINK_C
  140. typedef Rect *RectPtr, **RectHandle;
  141. #endif
  142.  
  143. struct    WindowTemplate    {                    /*template to a WIND resource*/
  144.     Rect    boundsRect;
  145.     short    procID;
  146.     Boolean    visible;
  147.     Boolean    filler1;
  148.     Boolean    goAwayFlag;
  149.     Boolean    filler2;
  150.     long    refCon;
  151.     Str255    title;
  152. };
  153. typedef    struct    WindowTemplate    WindowTemplate;
  154. typedef            WindowTemplate    *WindowTPtr, **WindowTHndl;
  155.  
  156. /* following is here to account for lapses in the THINK C headers */
  157.  
  158. #ifndef applec
  159. /*
  160. typedef unsigned char TrapType;
  161. */
  162. #ifndef THINK_C
  163. struct NumVersion {
  164.     unsigned char majorRev;         /* 1st part of version number in BCD*/
  165. /*    unsigned short minorRev : 4;        2nd part is 1 nibble in BCD*/
  166. /*    unsigned short bugFixRev : 4;         3rd part is 1 nibble in BCD*/
  167.     unsigned char minorAndBugFixRev;
  168.     unsigned char stage;            /*stage code: dev, alpha, beta, final*/
  169.     unsigned char nonRelRev;        /*revision level of non-released version*/
  170. };
  171.  
  172. typedef struct NumVersion NumVersion;
  173. /* Numeric version part of 'vers' resource */
  174. struct VersRec {
  175.     NumVersion numericVersion;        /*encoded version number*/
  176.     short countryCode;                /*country code from intl utilities*/
  177.     Str255 shortVersion;            /*version number string - worst case*/
  178.     Str255 reserved;                /*longMessage string packed after shortVersion*/
  179. };
  180.  
  181. typedef struct VersRec VersRec;
  182. typedef VersRec *VersRecPtr, **VersRecHndl;
  183.  
  184.  
  185. /*
  186. typedef WStateData *WStateDataPtr, **WStateDataHandle;
  187. */
  188.  
  189. #define Length(string) (*(unsigned char *)(string))
  190. #endif
  191.  
  192. #ifndef THINK_C
  193. #define Gestalt            GESTALT
  194. #define NewGestalt        NEWGESTALT
  195. #define ReplaceGestalt    REPLACEGESTALT
  196. #endif
  197. #endif
  198.  
  199.  
  200. typedef Rect (*PositionWndProcPtr)(WindowPtr window, WindowPtr relatedWindow);
  201.  
  202.  
  203. /*-----------------------------------------------------------------------------------------
  204.     Handy Macros/inlines
  205. -----------------------------------------------------------------------------------------*/
  206. #ifdef false                                        /* The c++ stuff is turned OFF!!! */
  207.  
  208. inline long abs(val) 
  209. {    return ((val < 0) ? (-val) : (val)); }            /* Absolute value */
  210.  
  211. inline void PStrCopy(dest, src)                        /* Pascal string copy */
  212. {    BlockMove (src, dest, (*(char *)(src))+1); }
  213.  
  214. inline Point* TopLeft(Rect& r)                        /* provide access to rect.topLeft  */
  215. {    return (Point*)(&r.top); }
  216.  
  217. inline Point* BotRight(Rect& r)                        /* provide access to rect.botRight  */
  218. {    return (Point*)(&r.bottom); }
  219.  
  220. inline short HiWrd(long aLong)                        /* return the hi word of a long */
  221. {    return ((aLong >> 16) & 0xFFFF); }
  222.  
  223. inline short LoWrd(long aLong)                        /* return the lo word of a long */
  224. {    return (aLong & 0xFFFF); }
  225.  
  226. inline void SETPT(Point *pt,short h,short v)
  227. {    (*pt).h = h; (*pt).v = v); }
  228.  
  229. inline void SETRECT(Rect *r,short left,short top,short right,short bottom)
  230. {    SETPT(TopLeft(*r), left, top); SETPT(BotRight(*r), right, bottom); }
  231.  
  232. /* 
  233.  *    Useful functions for testing gestalt attribute responses
  234.  *
  235.  *    BTstBool returns a true boolean value (0 or 1), but is slower than:
  236.  *    BTstQ which simply returns a non-zero value if the bit is set which
  237.  *    means the result could get lost if assigned to a short, for example.
  238.  *
  239.  *    arg is any integer value, bitnbr is the number of the bit to be tested.
  240.  *    bitnbr = 0 is the least significant bit.
  241.  */
  242. inline short BTstBool(arg, bitnbr)    
  243. {    return ((arg >> bitnbr) & 1); }
  244.  
  245. inline long BTstQ(arg, bitnbr)
  246. {    return (arg & (1 << bitnbr)); }
  247.  
  248. #else
  249.  
  250.  
  251. #ifndef THINK_C
  252. #define QD(whatever) (qd.##whatever)
  253. #else
  254. #define QD(whatever) (whatever)
  255. #endif
  256.  
  257.  
  258. /* define our own abs() so we don't need StdLib */
  259. #define abs(val) (((val) < 0) ? (-(val)) : (val))
  260. /* Pascal string copy */
  261. #define PStrCopy(dest, src)    (BlockMove (src, dest, (*(char *)(src))+1))
  262. #define TopLeft(r)        (* (Point *) &(r).top)
  263. #define BotRight(r)        (* (Point *) &(r).bottom)
  264. #define HiWrd(aLong)    (((aLong) >> 16) & 0xFFFF)
  265. #define LoWrd(aLong)    ((aLong) & 0xFFFF)
  266. #define MIN(a, b) ((a) < (b) ? (a) : (b) )
  267. #define MAX(a, b) ((a) > (b) ? (a) : (b) )
  268. #define SETPT(pt, x, y)    (*(pt)).h = (x); (*(pt)).v = (y)
  269. #define SETRECT(r, left, top, right, bottom)    \
  270.                         SETPT(&TopLeft(*(r)), (left), (top)); \
  271.                         SETPT(&BotRight(*(r)), (right), (bottom))
  272. /* 
  273.  *    Useful macros for testing gestalt attribute responses
  274.  *
  275.  *    BTstBool returns a true boolean value (0 or 1), but is slower than:
  276.  *    BTstQ which simply returns a non-zero value if the bit is set which
  277.  *    means the result could get lost if assigned to a short, for example.
  278.  *
  279.  *    arg is any integer value, bitnbr is the number of the bit to be tested.
  280.  *    bitnbr = 0 is the least significant bit.
  281.  */
  282. #define BTstBool(arg, bitnbr)    ((arg >> bitnbr) & 1)
  283. #define BTstQ(arg, bitnbr)        (arg & (1 << bitnbr))
  284.  
  285. #endif
  286.  
  287. /*-----------------------------------------------------------------------------------------
  288.     Global variables
  289. -----------------------------------------------------------------------------------------*/
  290. /*    The following global variables are initialized by StardardInitialization to
  291.  *    define the environnment.  This used to be a single SysEnvRec, but now,
  292.  *    all those variables defined in a SysEnvRec can be returned by Gestalt
  293.  *    (except sysVRefNum; see FindSysFolder).  Note that all the variables
  294.  *    below will be correctly initialized whether Gestalt is available or not;
  295.  *    the Gestalt glue handles this.
  296.  */
  297. extern short            gMachineType;            /* which machine this is */
  298. extern short            gSystemVersion;            /* System version number */
  299. extern short            gProcessorType;            /* which CPU this is */
  300. extern Boolean            gHasFPU;                /* true if machine has an FPU */
  301. extern short            gQDVersion;                /* major QD version #; 0 for original, 
  302.                                                     1 for color QD, 2 for 32-bit QD */
  303. extern short            gKeyboardType;            /* which type of keyboard is present */
  304. extern short            gAppleTalkVersion;        /* AppleTalk version number */
  305.         
  306. /*    These are also handled by Gestalt. gHasPMMU has no corresponding SysEnvRec
  307.  *    field, but it is handled by the glue, so we include it here for completeness.
  308.  *    gAUXVersion will be initialized with Gestalt if present, but correctly
  309.  *    set even if Gestalt is not available
  310.  */
  311. extern Boolean            gHasPMMU;                /* true if machine has a PMMU or equivalent */
  312. extern short            gAUXVersion;            /* major A/UX version number (0 if not present) */
  313.  
  314. /*    
  315.  *    gHasWaitNextEvent is set to TRUE if the Macintosh we are running on has
  316.  *    WaitNextEvent implemented. We can use this in our main event loop to
  317.  *    determine whether to call WaitNextEvent or GetNextEvent.
  318.  */
  319. extern Boolean            gHasWaitNextEvent;
  320.  
  321. /*
  322.  *    gAppResRef is the application’s resource file reference. I need to save
  323.  *    this since I can open other resource files. The current resource file is
  324.  *    always gAppResRef unless I momentarily set it to another file to read its
  325.  *    resources, and then immediately restore it back.
  326.  */
  327. extern short            gAppResRef;
  328.  
  329. /*
  330.  *    gInBackground is maintained by our osEvent handling routines. Any part of
  331.  *    the program can check it to find out if it is currently in the background.
  332.  */
  333. extern Boolean            gInBackground;            /* maintained by StandardInitialization
  334.                                                       and DoEvent */
  335.                                                       
  336. /*
  337.  *    gAppName holds the name of the application that's running. You can use if
  338.  *    for any purpose you'd like. It is also used by StandardAbout if it can't
  339.  *    find a string to use for the application name in a resource, so make sure
  340.  *    you call InitForStandardAbout if you are going to call StandardAbout. If you
  341.  *    call StandardInitialization, this is done for you.
  342.  */
  343. extern Str255            gAppName;
  344.  
  345. /*
  346.  *    gSignature holds the creator signature for the running application. It follows the
  347.  *    same rules as those for gAppName.
  348.  */
  349. extern OSType            gSignature;
  350.  
  351. /*
  352.  *    Initial values of these global variables are set to zero or FALSE by MPW's 
  353.  *    runtime initialization routines.  If the Utilities initialization routines
  354.  *    have been properly called, then gUtilitiesInited will be true.  If it is
  355.  *    not true, then the values of the above global variables are invalid.
  356.  */
  357. extern Boolean            gUtilitiesInited;
  358.  
  359. /*-----------------------------------------------------------------------------------------
  360.     Interface to routines
  361. -----------------------------------------------------------------------------------------*/
  362.  
  363. #ifdef __cplusplus
  364. extern "C" {
  365. #endif
  366.  
  367. short        CenteredAlert(short alertID, WindowPtr relWindow);
  368.             /* Given an Alert ID and a related window pointer, this routine will center
  369.                the alert on the same device as the related window.  If the related
  370.                window pointer is nil, then the alert will be centered on the device
  371.                that the alert would normally be placed if Alert was called directly. */
  372.  
  373. void        CenterRectInRect(Rect outerRect, Rect *innerRect);
  374.             /* Given two rectangles, this routine centers the second one within the first. */
  375.  
  376. Rect        CenterWindow(WindowPtr window, WindowPtr relatedWindow);
  377.             /* Given a window pointer and a related window pointer, this routine will
  378.                center the window on the same device as the related window.  If the
  379.                related window pointer is nil, then the window will be centered on the
  380.                device that the window already is.
  381.                WARNING: This routine may move or purge memory. */
  382.  
  383. void        CloseAnyWindow(WindowPtr window);
  384.             /* Closes the indicated window.  Does the right thing, taking into account
  385.                that the window may belong to a DA.
  386.                WARNING: An application window is closed via a CloseWindow call.  Use
  387.                            this call when you want to keep the storage for the window
  388.                         record.  (Compare against DisposeAnyWindow.) */
  389.  
  390. void        DisposeAnyWindow(WindowPtr window);
  391.             /* Disposes of the indicated window.  Does the right thing, taking into account
  392.                that the window may belong to a DA.
  393.                WARNING: An application window is closed via a DisposeWindow call.  Use
  394.                            this call when you want to free up the storage for the window
  395.                         record.  (Compare against CloseAnyWindow.) */
  396.  
  397. void        DeathAlert(short errResID, short errStringIndex);
  398.             /* Display an alert that tells the user an error occurred, then exit the
  399.                program. This routine is used as an ultimate bail-out for serious errors
  400.                that prohibit the continuation of the application. */ 
  401.  
  402. void        DeathAlertMessage(short errResID, short errStringIndex, short message);
  403.  
  404. void        ErrorAlert(short errResID, short errStringIndex);
  405.  
  406. void        ErrorAlertMessage(short errResID, short errStringIndex, short message);
  407.  
  408. OSErr        FindSysFolder(short *foundVRefNum, long *foundDirID);
  409.             /* FindSysFolder returns the (real) vRefNum, and the DirID of the current
  410.                system folder.  It uses the Folder Manager if present, otherwise
  411.                it falls back to SysEnvirons.  It returns zero on success, otherwise
  412.                a standard system error. */
  413.  
  414. Handle        GetAppIndResource(ResType theType, short index, OSErr *err);
  415.             /* GetAppIndResource gets a resource from the application's res file by index */
  416.  
  417. Handle        GetAppNamedResource(ResType theType, Str255 name, OSErr *err);
  418.             /* GetAppNamedResource gets a resource from the application's res file by name */
  419.  
  420. Handle        GetAppResource(ResType theType, short theID, OSErr *err);
  421.             /* GetAppResource gets a resource from the application's res file by resource ID */
  422.  
  423. short        GetAUXVersion( void);
  424.             /* getAUXVersion -- Checks for the presence of A/UX by whatever means is
  425.                appropriate.  Returns the major version number of A/UX (i.e. 0 if A/UX 
  426.                is not present, 1 for any 1.x.x version 2 for any 2.x version, etc.
  427.                This code should work for all past, present and future A/UX systems. */
  428.  
  429. DialogPtr    GetCenteredDialog(short id, DialogPtr storage, WindowPtr relatedWindow, WindowPtr behind);
  430.             /* Given a dialog ID and a related window pointer, this routine will center
  431.                the dialog on the same device as the related window.  If the related
  432.                window pointer is nil, then the dialog will be centered on the device
  433.                that the dialog would normally be placed if GetNewDialog was called. */
  434.  
  435. WindowPtr    GetCenteredWindow(short id, Ptr storage, WindowPtr relWindow, WindowPtr behind, Boolean inColor);
  436.             /* Given a window ID and a related window pointer, this routine will center
  437.                the window on the same device as the related window.  If the related
  438.                window pointer is nil, then the window will be centered on the device
  439.                that the window would normally be placed if GetNewWindow was called. */
  440.  
  441. Boolean     GetCheckOrRadio(DialogPtr dlgPtr, short itemNo);
  442.  
  443. long        GetGestaltResult(OSType gestaltSelector);
  444.             /* GetGestaltResult returns the result value from Gestalt for the specified
  445.                selector.  If Gestalt returned an error GetGestaltResult returns zero.  Use 
  446.                of this function is only cool if we don't care whether Gestalt returned an 
  447.                error.  In many casesyou may need to know the exact Gestalt error code so 
  448.                then this routine would be inappropriate. */
  449.  
  450. Point        GetGlobalMouse(void);
  451.             /* Returns the location of the mouse in local coordinates. It does this by
  452.                calling OSEventAvail(). */ 
  453.  
  454. Point        GetGlobalTopLeft(WindowPtr window);
  455.             /*     Given a window, this will return the top left point of the window’s port in
  456.                   global coordinates. Something this doesn’t include, is the window’s drag
  457.                   region (or title bar). This returns the top left point of the window’s
  458.                   content area only. */
  459.  
  460. long        GetKFreeSpace(short vRefNum);
  461.  
  462. Rect        GetMainScreenRect(void);
  463.  
  464. GDHandle    GetRectDevice(Rect globalRect);
  465.             /* Find the greatest overlap device for the given global rectangle. */
  466.  
  467. Rect        GetRectDeviceRect(Rect globalRect);
  468.             /* Find the rect of the greatest overlap device for the given global rect. */
  469.  
  470. WindowPtr    GetSomeKindOfWindow(PositionWndProcPtr whatKind, short windID, Ptr storage, WindowPtr relWindow, WindowPtr behind, Boolean inColor);
  471.             /* Given a window positioning procedure pointer, a window ID and a window
  472.                pointer the window relates to, this function open a new window by either
  473.                a NewCWindow or a NewWindow call, depending on the value of inColor.  The
  474.                window will be opened invisible, independent of what the resource says.
  475.                Once the window is opened successfully, the positioning procedure is
  476.                called.  The positioning procedure is passed a pointer to the just-opened
  477.                invisible window and a pointer to the related window.  It is up to the
  478.                positioning procedure to move the invisible window to the correct location
  479.                on the correct device.  Once the positioning procedure returns, the window
  480.                will be made visible if so indicated by the resource. */
  481.  
  482. WindowPtr    GetStaggeredWindow(short id, Ptr storage, WindowPtr relWindow, WindowPtr behind, Boolean inColor);
  483.             /* Given a window ID and a window pointer the window relates to, this function
  484.                will stagger the window’s rectangle before showing it on the proper screen.
  485.                This follows the Apple Human Interface Guidelines for where to place a
  486.                staggered window on the screen.  If the window is not closely associated
  487.                with another window, pass a nil for the window pointer of the related
  488.                window.  If you pass a nil, the window is simply displayed where the
  489.                resource would indicate. */
  490.  
  491. TrapType    GetTrapType(short theTrap);
  492.             /* Returns the type (OSType or ToolType) of the trap. It does this by checking
  493.                the bits of the trap word. */ 
  494.  
  495. Rect        GetWindowContentRect(WindowPtr window);
  496.             /* Given a window pointer, return the global rectangle that encloses the
  497.                content area of the window. */
  498.  
  499. short        GetWindowCount(Boolean includeDAs, Boolean includeInvisibles);
  500.             /* This procedure counts the number of windows in the application plane.  You have the
  501.                choices of also including DAs and invisible windows in this count. */
  502.  
  503. GDHandle    GetWindowDevice(WindowPtr window);
  504.             /* Find the greatest overlap device for the given window. */
  505.  
  506. Rect        GetWindowDeviceRect(WindowPtr window);
  507.             /* Given a window pointer, find the device that contains most of the window
  508.                and return the device's bounding rectangle. */
  509.  
  510. Rect        GetWindowDeviceRectNMB(WindowPtr window);
  511.             /* Given a window pointer, find the device that contains most of the window
  512.                and return the device's bounding rectangle.  If this device is the main
  513.                device, then remove the menubar area from the rectangle. */
  514.  
  515. Rect        GetWindowStructureRect(WindowPtr window);
  516.             /* This procedure is used to get the rectangle that surrounds the entire
  517.                structure of a window.  This is true whether or not the window is visible.
  518.                If the window is visible, then it is a simple matter of using the bounding
  519.                rectangle of the structure region.  If the window is invisible, then the
  520.                strucRgn is not correct.  To make it correct, then window has to be moved
  521.                way off the screen and then made visible.  This generates a valid strucRgn,
  522.                although it is valid for the position that is way off the screen.  It still
  523.                needs to be offset back into the original position.  Once the bounding
  524.                rectangle for the strucRgn is obtained, the window can then be hidden again
  525.                and moved back to its correct location.  Note that ShowHide is used,
  526.                instead of ShowWindow and HideWindow.  HideWindow can change the plane of
  527.                the window.  Also, ShowHide does not affect the hiliting of windows. */
  528.   
  529. void        GlobalToLocalRect(Rect *aRect);
  530.  
  531. void        InitToolBox(void);
  532.  
  533. void        InitUtilities(void);
  534.             /* This sets up some global variables for use by the utilities package.  If you call
  535.                StandardInitialization, you don't need to call this, as it will do it for you. */ 
  536.  
  537. Boolean        IsAppWindow(WindowPtr window);
  538.             /* Returns TRUE if the windowKind of the window is greater than or equal to
  539.                userKind. If it is less, or the window is NIL, then return FALSE. */ 
  540.  
  541. Boolean        IsDAWindow(WindowPtr window);
  542.             /* Returns TRUE if the windowKind of the window is less than zero. If not, or
  543.                the window is NIL, then return FALSE. */ 
  544.  
  545. void        LocalToGlobalRect(Rect *aRect);
  546.  
  547. char        LockHandleHigh(Handle theHandle);
  548.             /* Does a MoveHHi on the handle and then locks it.  Also, the original state
  549.                of the handle is returned, so you can keep it and set the handle back to it's
  550.                original state with a HSetState call. */
  551.  
  552. short        NumToolboxTraps(void);
  553.             /* Determines the size of the Tool trap table. It does this by sampling a
  554.                couple of trap locations and seeing which, if any are Unimplemented. */ 
  555.  
  556. void        OutlineControl(ControlHandle button);
  557.  
  558. void         OutlineDialogItem(DialogPtr dlgPtr, short item);
  559.  
  560. void        PositionRectInRect(Rect outerRect, Rect *innerRect, Fixed horzRatio, Fixed vertRatio);
  561.             /* Given two rectangles, this routine positions the second within the first one
  562.                so that the it maintains the spacing specified the the horzRatio and vertRatio
  563.                parameters. In other words, to center an inner rectangle hoizontally, but
  564.                have its center be 1/3 from the top of the outer rectangle, call this
  565.                routine with horzRatio = FixRatio(1, 2), vertRatio = FixRatio(1, 3). */
  566.  
  567. void        PullApplicationToFront(void);
  568.             
  569. void        PStrConcat(Str255 targetStr, Str255 appendStr);
  570.             /* Concatenate a Pascal string onto another. */
  571.  
  572. void        SelectButton(ControlHandle button);
  573.             /* Given the button control handle, this will cause the button to look as if it
  574.                has been clicked in. This is nice to do for the user if they type return or
  575.                enter to select the default item. */
  576.  
  577. void        SetCheckOrRadioButton(DialogPtr dlgPtr, short itemNo, short state);
  578.  
  579. Rect        StaggerWindow(WindowPtr window, WindowPtr relatedWindow);
  580.             /* This algorithm for staggering windows does quite a good job.  It also is
  581.                quite gnarly.  Here's the deal:
  582.                There are pre-designated positions that we will try when positioning a
  583.                window.  These slots will be tried from the upper-left corner towards the
  584.                lower-right corner.  If there are other windows in that slot, then we will
  585.                consider that slot taken, and proceed to the next slot.  A slot is
  586.                determined to be taken by checking a point with a slop area.  This slop
  587.                area is diamond-shaped, not simply rectangular.  If there is no other
  588.                visible window with an upper-left corner within the slopt diamond, then
  589.                we are allowed to position our window there.
  590.                The above rule holds true unless this forces the window to be partly
  591.                off the screen.  If the window ends up partly off the screen, then we give
  592.                up and just put it in the first slot. */
  593.  
  594. void        StandardAbout(short appNameStringID);
  595.             /* Shows a standard about box with the name of the application, its version
  596.                number, a copyright notice, and DTS credits. Most of this information is
  597.                taking from a standard DITL and the application’s 'vers' resource. The name
  598.                of the application is taken either from the 'STR ' resource passed in to
  599.                this routine, or from GetAppParms() if that resource doesn’t exist, or you
  600.                pass in -1. */ 
  601.  
  602. void        StandardInitialization(short callsToMoreMasters);
  603.             /* Initializes “gInBackGround” to FALSE. Makes the following InitXXX calls:
  604.                InitGraf(), InitFonts(), InitWindows(), InitMenus(), TEInit(),
  605.                InitDialogs(), InitCursor(). Brings application to front with 3 EventAvail
  606.                calls. Calls SysEnvirons to initialize “gMac”. Calls TrapExists() to
  607.                initialize “gHasWaitNextEvent”. */ 
  608.    
  609. void        StandardMenuSetup(short MBARID, short AppleMenuID);
  610.             /* Installs and draws the menus indicated by 'MBAR'(MBARID). Adds DA’s to the
  611.                menu indicated by AppleMenuID by calling AddResMenu. If the menuBar cannot
  612.                be created, the alert specified by rDeathAlert is displayed. */   
  613.  
  614. void         ToggleCheck(DialogPtr dlgPtr, short cChkItem);
  615.  
  616. Boolean        TrapExists(short theTrap);
  617.             /* Returns TRUE if the trap exists (i.e., it’s callable without getting DS
  618.                error 12) */ 
  619.  
  620. void        ZoomToWindowDevice(WindowPtr window, short maxWidth, short maxHeight,
  621.                                short zoomDir, Boolean front);
  622.  
  623. #ifdef __cplusplus
  624. }
  625. #endif
  626.  
  627. #endif